<?php
class facebookHelper{
    private static $facebook;
    private function __construct() {/* empty */}
    public static function getInstance(){
        if(!isset(self::$facebook)){
            
            self::$facebook = new Facebook(array(
                'appId'  => FB_APP_ID,
                'secret' => FB_APP_SECRET
            ));
            
            self::$facebook->getSession();

        }
        return self::$facebook;
    }

    //Note : even if $entry is not exist, Facebook doesn't provide any error or message
    public static function callGraphAPI($entry){
        
        if(!isset(self::$facebook)){
            self::$facebook = self::getInstance();
        }
        
        $data = null;
        if(!empty($entry)){
            try{
                $data = self::$facebook->api($entry);
            }catch(FacebookApiException $e){
                throw $e;
            }
        }
        return $data;    
    }
    
    public static function callFQL($query){

        if(!isset(self::$facebook)){
            self::$facebook = self::getInstance();
        }
    
        $data = null;
        if(!empty($query)){
            try{
                $data = self::$facebook->api(array(
                    'method' => 'fql.query',
                    'query' => $query
                ));
            }catch(FacebookApiException $e){
                throw $e;
            }
        }
        return $data;
    
    }
    
    //Note : even if $entry is not exist, Facebook doesn't provide any error or message
    public static function callMultiFQL($queries){
        
        if(!isset(self::$facebook)){
            self::$facebook = self::getInstance();
        }
    
        $data = null;
        if(!empty($queries) && is_array($queries)){
            try{
                $data = self::$facebook->api(
                    array(
                    	'method' => 'fql.multiquery',
                        'queries' => $queries
                    )
                );
            }catch(FacebookApiException $e){
                throw $e;
            }
        }
        return $data;   
    }
}
?>